import 'package:dmz/base/pageWidget/base_stateful_widget.dart';
import 'package:dmz/base/widget/defult_widget.dart';
import 'package:dmz/business/home/model/moto_model.dart';
import 'package:dmz/business/mine/widget/garage_widgets.dart';
import 'package:dmz/utils/sp_utils.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

class MainWidget extends StatelessWidget {
  final List<MotoModel> motoList;
  final int selectIndex;
  const MainWidget(
      {super.key, required this.motoList, required this.selectIndex});

  @override
  Widget build(BuildContext context) {
    return motoList.length == 1
        ? GarageWidgets.emptyWidget()
        : Column(children: [firstItme(), otherListWidget()])
            .marginOnly(left: 32.sp, right: 32.sp, top: 46.sp);
  }

  firstItme() {
    Widget useingWidget() {
      return Container(
        alignment: Alignment.center,
        decoration: BoxDecoration(
          color: Color(0xFF23C565),
          borderRadius: BorderRadius.only(
              topRight: Radius.circular(56.sp),
              bottomLeft: Radius.circular(56.sp)), // 设置圆角半径
        ),
        width: 200.sp,
        height: 72.sp,
        child: DefaultText('使用中'.tr, 36.sp, textColor: Colors.white),
      );
    }

    return Stack(alignment: Alignment.topRight, children: [
      Container(
          alignment: Alignment.center,
          decoration: BoxDecoration(
              color: Color(0xFF434650),
              borderRadius: BorderRadius.circular(56.sp), // 设置圆角半径
              border: Border.all(
                color: Color(0xFF23C565), // 设置边框颜色
                width: 2.sp, // 设置边框宽度
              )),
          child: Column(children: [
            Container(
                    color: Color(0xFFA1A2A7),
                    child: DefaultNetWorkImage(
                        motoList[selectIndex].photo ?? '',
                        width: 296.sp,
                        height: 296.sp))
                .didClipRRectAll(296.sp)
                .marginOnly(top: 114.sp, bottom: 48.sp),
            DefaultText(motoList[selectIndex].name ?? '', 48.sp,
                textColor: Color(0xFFF9F9F9), fontWeight: FontWeight.w700),
            DefaultText(
                    SPUtils.timeIntToTimeStr(
                        motoList[selectIndex].created_at ?? 0,
                        attern: 'yyyy-MM-dd HH:mm'),
                    28.sp,
                    textColor: Color(0xFF999999))
                .marginOnly(bottom: 50.sp, top: 6.sp),
          ])),
      useingWidget()
    ]);
  }

  otherListWidget() {
    item(MotoModel data) {
      return Container(
          decoration: BoxDecoration(
            color: Color(0xFF434650),
            borderRadius: BorderRadius.circular(56.sp), // 设置圆角半径
          ),
          child: Row(children: [
            Container(
                    color: Color(0xFFA1A2A7),
                    child: DefaultNetWorkImage(
                        motoList[selectIndex].photo ?? '',
                        width: 112.sp,
                        height: 112.sp))
                .didClipRRectAll(112.sp)
                .marginOnly(
                    top: 40.sp, bottom: 40.sp, left: 32.sp, right: 32.sp),
            Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
              DefaultText(data.name, 48.sp,
                  textColor: Color(0xFFF9F9F9), fontWeight: FontWeight.w700),
              DefaultText(
                  SPUtils.timeIntToTimeStr(data.created_at ?? 0,
                      attern: 'yyyy-MM-dd HH:mm'),
                  28.sp,
                  textColor: Color(0xFF999999))
            ])
          ]));
    }

    List<MotoModel> motos = [];
    motos.addAll(motoList);
    motos.removeAt(selectIndex);

    return Expanded(
        child: ListView(
            children: List.generate(
                motoList.length < 2 ? 0 : motoList.length - 2,
                (index) => item(motos[index]))));
  }
}
